{include file='forms/default.tpl'}
	
{literal}
<script type='text/javascript'>

	function getFieldType(){
		return ($('#attribute_field_type_id option:selected').val());
	}

	function showDefaultValuesForm(){
		
		$('#values_container').parent().parent().remove();
		
		var currentType = getFieldType();
		if(currentType=='radio' || currentType=='select'){

			$('#attribute_field_type_id').parent().parent().after("<tr>"+
				"<td></td>"+
				"<td><div style='border:1px solid silver;padding:5px;width:310px'>"+
					"<div id='values_container' style='overflow:hidden'><strong>Values For Attribute</strong><div style='height:10px'></div><div style='float:left;'>Attribute Text:<br/><input style='width:135px' type='text' name='value_text[]'/></div><div style='float:left;'>Attribute Value:<br/><input style='width:135px' type='text' name='value_value[]'/></div></div><a href='#' onclick='addValuesRow();return false;'>Add</a>"+
				"</div></td>"+
			"</tr>");			
			
{/literal}
		{if $exist_values}
			$('#values_container input').replaceWith("<div style='width:140px'></div>");
			{foreach from=$exist_values item=value}
			$('#values_container').append("<div><input type='hidden' name='value_id[]' value='{$value.value_id}'><input style='width:135px' type='text' name='value_text[]' value='{$value.value_text}'/><input type='text' style='width:135px' name='value_value[]' value='{$value.value_value}'/><a href='#' onclick=\"if(!confirm('Are you sure?')){ldelim}return false{rdelim}else{ldelim}deleteValueRow(this,'{$value.value_id}');return false;{rdelim}\">Del</a></div>");			
			{/foreach}
		{/if}	
{literal}			
			
		}
	}

	function addValuesRow(){
		$('#values_container').append("<div><input style='width:135px' type='text' name='value_text[]'/><input type='text' style='width:135px' name='value_value[]'/><a href='#' onclick=\"if(!confirm('Are you sure?')){return false}else{deleteValueRow(this);return false;}\">Del</a></div>");
	}

	function deleteValueRow(del_button_object){
		if(arguments[1]){
			$.ajax({
	            type: "GET",
	            url: "/admin/productattributes/deletevalue/value_id/"+arguments[1],
	            dataType: "json",
	            success : deleteValueRowAfterAjax
     		});
		}else{
			$(del_button_object).parent().remove();
			if($('input[name="value_text[]"]').length==0){
				addValuesRow();
			}			
		}	
	}

	function deleteValueRowAfterAjax(json){
		$('input[name="value_id[]"][value="'+json.value_id+'"]').parent().remove();
		if($('input[name="value_text[]"]').length==0){
			addValuesRow();
		}
	}

	$(document).ready(function(){  
		showDefaultValuesForm();
		$('#attribute_field_type_id').bind('change',function(e){showDefaultValuesForm()});
	});  
</script>	
{/literal}
